<template>
  <div class="home">
    <el-container>
      <el-header>
        <h3>
          <img src="../assets/logo.png"
               alt="" />
          <span>电商后台管理系统</span>
        </h3>
        <el-button type="info"
                   @click="layout">退出</el-button>
      </el-header>
      <el-container>
        <el-aside :width="flag ? '64px' : '200px'">
          <p @click="flag=!flag">|&nbsp;|&nbsp;|</p>
          <el-menu class="el-menu-vertical-demo"
                   background-color="#545c64"
                   text-color="#fff"
                   unique-opened
                   :collapse-transition="false"
                   :collapse="flag"
                   router>
            <el-submenu :index="item.id + ''"
                        v-for="item in menuList"
                        :key="item.id">
              <template slot="title">
                <i :class="iconList[item.id]"></i>
                <span>{{item.authName}}</span>
              </template>
              <el-menu-item :index="it.path"
                            v-for="it in item.children"
                            :key="it.id">
                <span href="javascript:;"
                      @click="getpage(item.authName, it.authName)">
                  <i class="el-icon-location"></i>
                  {{it.authName}}
                </span>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      menuList: [],
      iconList: {
        125: 'el-icon-user-solid',
        103: 'el-icon-document-copy',
        101: 'el-icon-s-goods',
        102: 'el-icon-tickets',
        145: 'el-icon-data-line',
      },
      flag: false,
    }
  },
  mounted() {
    this.getdata()
  },
  methods: {
    layout() {
      sessionStorage.clear()
      this.$router.push('/login')
    },
    async getdata() {
      var res = await this.$http.get('/menus')
      // console.log(res);
      this.menuList = res.data.data
    },
    getpage(one, two) {
      var obj = { one: one, two: two }
      sessionStorage.setItem('path', JSON.stringify(obj))
    },
  },
}
</script>

<style lang="scss" scoped>
.home {
  width: 100%;
  height: 100%;
  & > .el-container {
    width: 100%;
    height: 100%;
  }
}
.el-header {
  background-color: #373d41;
  color: #333;
  text-align: center;
  line-height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  h3 {
    color: #fff;
    font-weight: bolder;
    display: flex;
    justify-content: center;
    align-items: center;
    img {
      width: 61px;
      height: 56px;
      border-radius: 50%;
      margin-right: 15px;
    }
  }
}

.el-aside {
  background-color: #333744;
  color: #333;
  text-align: center;
  p {
    width: 100%;
    color: #fff;
    background-color: #4a5064;
    padding: 5px;
    font-size: 14px;
    box-sizing: border-box;
  }
  .el-menu {
    border: none;
  }
}

.el-main {
  background-color: #eaedf1;
  color: #333;
}
</style>